﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Model;
using University.Workshop.Business;
using University.Workshop.Presenters;
using University.Workshop.Presenters.PatientFolder;

namespace University.Workshop.WinApp
{
    public partial class PatientHistory : Form, IPatientHistory, ISearchConsultation 
    {
        string IdPatient;
        int index;
        long consultationid;
        List<Consultation> consultation;
        PresenterPatientHistory presenterPatientHistory;
        PresenterSearchConsultation presenterConsultation;
        public PatientHistory(string IdPatient)
        {
            InitializeComponent();
            this.IdPatient = IdPatient;
            presenterPatientHistory = new PresenterPatientHistory(this);
            presenterConsultation = new PresenterSearchConsultation(this);
        }

        private void PatientHistory_Load(object sender, EventArgs e)
        {
            index = -1;
            dataConsultation.DataSource = null;
            Patient patient = presenterPatientHistory.ShowPatient();
            label1.Text = patient.PatientId;
            label2.Text = patient.FirstName;
            label3.Text = patient.FatherLastName;
            label4.Text = patient.MotherLastName;
            label5.Text = patient.LandPhone;
            label6.Text = patient.CellPhone;
            label7.Text = patient.Address;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        #region Miembros de IPatientHistory

        string IPatientHistory.PatientId
        {
            get
            {
                return IdPatient;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion

        private void button3_Click(object sender, EventArgs e)
        {
            consultation = (List<Consultation>)presenterConsultation.SearchConsultation();
            dataConsultation.DataSource = consultation;
        }

        #region Miembros de ISearchConsultation

        string ISearchConsultation.PatientId
        {
            get
            {
                return IdPatient;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion

        private void dataConsultation_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            index = e.RowIndex;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (index != -1)
                {

                    label18.Text = dataConsultation.CurrentRow.Cells["ConsultationId"].Value.ToString();
                    consultationid = long.Parse(label18.Text);
                    showConsultation showconsultation = new showConsultation(consultationid);
                    this.Visible = false;
                    if (showconsultation.ShowDialog() == DialogResult.Cancel)
                        this.Visible = true;
                    index = -1;
                    dataConsultation.DataSource = null;
                }
                else
                {
                    MessageBox.Show("Seleccione una Consulta");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
